﻿using SmartSapce.ServiceLocation;
using SmartSpace.Core;
using SmartSpace.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SmartSpace.WebApp._console.page
{
    public partial class page_add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ICoreService service = ServiceLocator.Get<ICoreService>();
                PagedList<PageTemplate> templates = service.GetPageTemplates(0, 999);

                _ctlListTemplates.DataSource = templates;
                _ctlListTemplates.DataBind();
            }
        }

        protected void _ctlBtnSave_Click(object sender, EventArgs e)
        {
            VirtualPage page = new VirtualPage();
            page.Id = Guid.NewGuid();
            page.AppId = SsSite.Application.Id;
            page.Name = _ctlEditName.Text;
            page.Caption = _ctlEditCaption.Text;
            page.TemplateId = new Guid(_ctlListTemplates.SelectedValue);

            ICoreService service = ServiceLocator.Get<ICoreService>();
            if (service.SavePage(page))
            {
                Response.Redirect("./page-list.aspx");
            }
        }
    }
}